/**
 * Created by Taller on 2017/7/27.
 */
var header = {
    "Content-Type": "application/json; charset=utf-8",
    "Accept-Language": "zh-CN",
    "token":""
};
var ajax = {
    send:function (request) {
        return send(request);
    },
    get:function (request) {
        request.method = 'get';
        return send(request);
    },
    post:function (request) {
        request.method = 'post';
        return send(request);
    },
    delete:function (request) {
        request.method = 'delete';
        return send(request);
    },
    put:function (request) {
        request.method = 'put';
        return send(request);
    },
    info:function (request) {
        request.method = 'info';
        return send(request);
    }
}

function send(request) {
    return $.ajax({
        type : request.method,
        url : request.url,
        data: ajaxEmpty(request.data),
        async: typeof(request.async)=="undefined" ? 'true' : request.async,
        contentType: "json",
        cache: false,
        headers: header,
        dataType:'json',
        beforeSend: function (xhr) {
            loading.show();
        },
        statusCode:{
            400: function () {
                loading.hide();
            },
            403: function () {
                loading.hide();
            },
            404: function () {
                loading.hide();
            },
            405: function () {
                loading.hide();
            },
            415: function () {
                loading.hide();
            },
            500: function () {
                loading.hide();
            },
            200: function () {
                loading.hide();
            }
        }
    });
}
function ajaxEmpty(value) {
    if(typeof(value)=="undefined")
        return "";
    if(typeof(value)=="object")
        return JSON.stringify(value);
    return value;
}